package ui.panel.equips
{

	import beans.WarriorBean;

	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Rectangle;

	import globals.ButtonType;
	import globals.Global;

	import ui.component.Button;
	import ui.component.GameTextField;
	import ui.component.Label;
	import ui.component.Page;
	import ui.component.ScaleBitmap;
	import ui.component.TextButton;
	import ui.face.Bar;
	import ui.panel.EquipPanel;

	import util.TextStyle;
	import util.UIUtil;

	/**
	 * 装备时的英雄信息。
	 * @author luguobin
	 */
	public class EquipWarriorInfo extends Sprite
	{

		private var _nameLabel:GameTextField;
		private var _jobLabel:GameTextField; //职位，等级
		private var _heroListBtn:TextButton;
		private var _hero:Bitmap;
		private var _gridItems:Array = [];
		private var _gridLabels:Array = [];
		private var _btnItems:Array = [];
		private var warriorBean:WarriorBean;

		public function EquipWarriorInfo()
		{
			super();

			var bg:ScaleBitmap = new ScaleBitmap(Global.assetsManager.getAssetsAsBitmapData("tower_bg"));
			bg.scale9Grid = new Rectangle(35, 35, 14, 14);
			bg.width = 150;
			bg.height = 335;
			this.addChild(bg);

			_hero = new Bitmap();
			_hero.y = 15;
			this.addChild(_hero);

			_nameLabel = new GameTextField();
			_nameLabel.defaultTextFormat = TextStyle.getTextFormat(0xFFFFFF, 12, true, "center");
			_nameLabel.width = bg.width;
			_nameLabel.y = 115;
			this.addChild(_nameLabel);
			_jobLabel = new GameTextField();
			_jobLabel.defaultTextFormat = TextStyle.getTextFormat(0xFFFFFF, 12, false, "center");
			_jobLabel.width = bg.width;
			_jobLabel.y = 135;
			this.addChild(_jobLabel);

			var gridTxts:Array = ["武器", "饰品", "道具"];

			for(var i:int = 0; i < 3; i++)
			{
				var grid:Bitmap = new Bitmap();
				grid.x = 33;
				grid.y = 165 + i * 40;
				this.addChild(grid);
				_gridItems.push(grid);

				var label:GameTextField = new GameTextField();
				label.defaultTextFormat = TextStyle.getTextFormat();
				TextStyle.addTextFrame(label, 0x000000);
				label.x = 35;
				label.y = 170 + i * 40;
				label.mytext = gridTxts[i];
				this.addChild(label);
				_gridLabels.push(label);

				var btn:TextButton = UIUtil.getTextButton(i, "强化", ButtonType.BUTTON_GREEN_SMALL, btnHandle);
				btn.x = 68;
				btn.y = 166 + i * 40;
				btn.enable = false;
				this.addChild(btn);
				_btnItems.push(btn);
			}

			_heroListBtn = UIUtil.getTextButton(3, "英雄列表", ButtonType.BUTTON_YELLOW, btnHandle);
			_heroListBtn.x = (bg.width - _heroListBtn.width) * 0.5;
			_heroListBtn.y = 286;
			this.addChild(_heroListBtn);
			//TODO:测试
			var bean:WarriorBean = new WarriorBean();
			bean.name = "阿波罗";
			bean.job = "太阳神";
			bean.image = "avatar_1_1";
			bean.level = 10;
			bean.exp = 20;
			bean.power = 300;
			bean.magic = 400;
			update(bean);
		}

		private function btnHandle(button:TextButton):void
		{
			switch(button.id)
			{
				case 0:
					break;
				case 1:
					break;
				case 2:
					break;
				case 3:
					Global.uiManager.equipPanel.popUpHeroList();
					break;
			}
		}

		private function presenceHandler(button:Button):void
		{
			if(warriorBean != null)
			{
			}
		}

		public function update(bean:WarriorBean):void
		{
			warriorBean = bean;

			_nameLabel.text = bean.name;
			_jobLabel.text = bean.job;

			_hero.bitmapData = Global.assetsManager.getAssetsAsBitmapData(bean.image, "warrior");
			_hero.x = (this.width - _hero.width) / 2;

			_gridItems[0].bitmapData = _gridItems[1].bitmapData = _gridItems[2].bitmapData = Global.assetsManager.getAssetsAsBitmapData("skill_bg");
		}

		private function pageHandler(num:uint):void
		{

		}

		public function clear():void
		{
			warriorBean = null;

//			nameLabel.text = jobLabel.text = levelLabel.text = "";
			_hero.bitmapData = null;
		}
	}
}